#include "head.h" 
void menu(Node *phead_W, Node *phead_F){
	while(1){
        system("cls");
        printf("\n\t\t教工工资管理系统\n");
        printf("\t-----------------------------\n");
        printf("\t\t1---输入数据\n");
        printf("\t\t2---修改数据\n");
        printf("\t\t3---删除数据\n");
        printf("\t\t4---查询数据\n");
        printf("\t\t5---统计数据\n");
        printf("\t\t6---插入数据\n");
		printf("\t\t7---输出数据\n"); 
		printf("\t\t8---计算数据\n");
		printf("\t\t9---打印表格\n");
        printf("\t\t0---退出\n");  
        printf("\t-----------------------------\n");
        printf("\t   请输入数字(0 - 8):");
        int choice;
        while(scanf("%d", &choice) == 0){
			printf("\t   输入错误！\n\t   请输入数字(0 - 8):");
			fflush(stdin);
		}
        switch (choice){
        	case 0:  return; 
            case 1:
            {
            	menu1(phead_W, phead_F);
            	break; 
            }
            case 2:
            {
            	menu2(phead_F);
            	break;
            }
            case 3:
            {
            	menu3(phead_F);
            	break;
            }
            case 4:
            {
            	menu4(phead_F);
            	break;
            }
            case 5:
            {
            	menu5(phead_F);
            	break;
            }
            case 6:
            {
            	menu6(phead_F);
            	break;
            }
            case 7:
            {
            	menu7(phead_W, phead_F);
            	break;
            }
            case 8:
            {
            	menu8(phead_W, phead_F);
            	break;
            }
            case 9:
			{
            	menu9(phead_W, phead_F);
				break;
			} 
			default: continue;
        }
        system("pause");
    }
	return;
}
void menu1(Node *phead_W, Node *phead_F){
	while (1){
		system("cls");
		printf("\n\t\t输入数据\n");
		printf("\t-----------------------------\n");
    	printf("\t\t1---输入工资补贴数据\n");
    	printf("\t\t2---输入教工数据\n");
    	printf("\t\t0---退出\n");
    	printf("\t-----------------------------\n");
    	printf("\t   请输入数字(0 - 2):");
        int choice;
        while(scanf("%d", &choice) == 0){
			printf("\t   输入错误！\n\t   请输入数字(0 - 2):");
			fflush(stdin);
		}
        switch (choice){
        	case 0:  return;
            case 1:
            {
            	addAll(phead_W, intput_W);
            	break; 
            }
            case 2:
            {
            	int n;
            	printf("输入人数：");scanf("%d", &n);
				for(int i = 0;i < n;i++){
					addAll(phead_F, intput_F);
				} 
            	break;
			} 
     		default: continue;
        }
        system("pause");
    }
	return;
}
void menu2(Node *phead_F){
	while (1){
		system("cls");
		printf("\n\t\t修改数据\n");
		printf("\t-----------------------------\n");
    	printf("\t\t1---修改第一个数据\n");
    	printf("\t\t2---修改最后一个数据\n");
    	printf("\t\t3---修改指定数据\n");
    	printf("\t\t0---退出\n");
    	printf("\t-----------------------------\n");
    	printf("\t   请输入数字(0 - 3):");
        int choice;
        while(scanf("%d", &choice) == 0){
			printf("\t   输入错误！\n\t   请输入数字(0 - 3):");
			fflush(stdin);
		}
        switch (choice){
        	case 0:  return; 
            case 1:
            {
            	if(phead_F->next == NULL){
            		printf("修改失败!\n");
				}
				else{
					change_first(phead_F);
            		printf("修改成功！\n");
				}
            	break;
            }
            case 2:
            {
            	if(phead_F->next == NULL){
            		printf("修改失败!\n");
				}
				else{
					change_late(phead_F);
            		printf("修改成功！\n");
				}
            	break;
			} 
			case 3:{
				char str[z];
				printf("请输入姓名：");scanf("%s", str); 
				change(phead_F, str);
				break;
			} 
     		default: continue;
        }
        system("pause");
    }
	return;
}
void menu3(Node *phead_F){
	while (1){
		system("cls");
		printf("\n\t\t删除数据\n");
		printf("\t-----------------------------\n");
    	printf("\t\t1---删除第一个数据\n");
    	printf("\t\t2---删除最后一个数据\n");
    	printf("\t\t3---删除指定数据\n");
    	printf("\t\t0---退出\n");
    	printf("\t-----------------------------\n");
    	printf("\t   请输入数字(0 - 3):");
        int choice;
        while(scanf("%d", &choice) == 0){
			printf("\t   输入错误！\n\t   请输入数字(0 - 3):");
			fflush(stdin);
		}
        switch (choice){
        	case 0:  return; 
            case 1:
            {
            	if(phead_F->next == NULL){
            		printf("删除失败!\n");
				}
				else{
					remove_first(phead_F);
            		printf("删除成功！\n");
				}
            	break; 
            }
            case 2:
            {
            	if(phead_F->next == NULL){
            		printf("删除失败!\n");
				}
				else{
					remove_late(phead_F);
            		printf("删除成功！\n");
				}
            	break;
			} 
			case 3:{
				char str[z];
				printf("请输入姓名：");scanf("%s", str); 
				remove(phead_F, str);
				break;
			} 
     		default: continue;
        }
        system("pause");
    }
	return;
}
void menu4(Node *phead_F){
	while (1){
		system("cls");
		printf("\n\t\t查询数据\n");
		printf("\t-----------------------------\n");
    	printf("\t\t1---查询第一个数据\n");
    	printf("\t\t2---查询最后一个数据\n");
    	printf("\t\t3---查询指定数据\n");
    	printf("\t\t0---退出\n");
    	printf("\t-----------------------------\n");
    	printf("\t   请输入数字(0 - 3):");
        int choice;
        while(scanf("%d", &choice) == 0){
			printf("\t   输入错误！\n\t   请输入数字(0 - 3):");
			fflush(stdin);
		}
        switch (choice){
        	case 0:  return; 
            case 1:
            {
            	if(phead_F->next == NULL){
            		printf("查无此人!\n");
				}
				else{
					find_first(phead_F);
				}
            	break; 
            }
            case 2:
            {
            	if(phead_F->next == NULL){
            		printf("查无此人!\n");
				}
				else{
					find_late(phead_F);
				}
            	break;
			} 
			case 3:{
				char str[z];
				printf("请输入姓名：");scanf("%s", str); 
				remove(phead_F, str);
				break;
			} 
     		default: continue;
        }
        system("pause");
    }
	return;
}
void menu5(Node *phead_F){
	while (1){
		system("cls");
		printf("\n\t\t统计数据\n");
		printf("\t-----------------------------\n");
    	printf("\t\t1---统计男，女性别人数\n");
    	printf("\t\t2---统计民族人数\n");
    	printf("\t\t3---统计部门人数\n");
    	printf("\t\t4---统计不同文化程度人数\n");
    	printf("\t\t0---退出\n");
    	printf("\t-----------------------------\n");
    	printf("\t   请输入数字(0 - 4):");
        int choice;
        while(scanf("%d", &choice) == 0){
			printf("\t   输入错误！\n\t   请输入数字(0 - 4):");
			fflush(stdin);
		}
        switch (choice){
        	case 0:  return; 
            case 1:
            {
            	statistics_sex(phead_F);
            	break; 
            }
            case 2:
            {
            	char str[z];
            	printf("请输入民族：");scanf("%s", str);
            	statistics_nation(phead_F, str);
            	break;
			} 
			case 3:
            {
            	char str[z];
            	printf("请输入部门：");scanf("%s", str);
            	statistics_sector(phead_F, str);
            	break;
			} 
			case 4:
            {
            	char str[z];
            	printf("请输入文化程度：");scanf("%s", str);
            	statistics_culturn(phead_F, str);
            	break;
			} 
     		default: continue;
        }
        system("pause");
    }
	return;
}
void menu6(Node *phead_F){
	while (1){
		system("cls");
		printf("\n\t\t插入数据\n");
		printf("\t-----------------------------\n");
    	printf("\t\t1---插入到第一个教工前面\n");
    	printf("\t\t2---插入到最后一个教工后面\n");
    	printf("\t\t3---插入到指定教工后\n");
    	printf("\t\t0---退出\n");
    	printf("\t-----------------------------\n");
    	printf("\t   请输入数字(0 - 3):");
        int choice;
        while(scanf("%d", &choice) == 0){
			printf("\t   输入错误！\n\t   请输入数字(0 - 3):");
			fflush(stdin);
		}
        switch (choice){
        	case 0:  return; 
            case 1:
            {
            	if(phead_F->next == NULL){
            		printf("插入失败!\n");
				}
				else{
            		insert_first(phead_F);
            	}
            	break; 
            }
            case 2:
            {
            	if(phead_F->next == NULL){
            		printf("插入失败!\n");
				}
				else{
					insert_late(phead_F);
				}
            	break;
			} 
			case 3:{
				char str[z];
				printf("请输入姓名：");scanf("%s", str); 
				insert(phead_F, str);
				break;
			} 
     		default: continue;
        }
        system("pause");
    }
	return;
}
void menu7(Node *phead_W, Node *phead_F){
	while (1){
		system("cls");
		printf("\n\t\t输出数据\n");
		printf("\t-----------------------------\n");
    	printf("\t\t1---输出工资补贴数据\n");
    	printf("\t\t2---输出教工数据\n");
    	printf("\t\t0---退出\n");
    	printf("\t-----------------------------\n");
    	printf("\t   请输入数字(0 - 2):");
        int choice;
        while(scanf("%d", &choice) == 0){
			printf("\t   输入错误！\n\t   请输入数字(0 - 2):");
			fflush(stdin);
		}
        switch (choice){
        	case 0:  return; 
            case 1:
            {
            	traversal(phead_W, show_W);
            	break; 
            }
            case 2:
            {
				traversal(phead_F, show_F);
            	break;
			} 
     		default: continue;
        }
        system("pause");
    }
	return;
}
void menu8(Node *phead_W, Node *phead_F){
	while (1){
		system("cls");
		printf("\n\t\t计算数据\n");
		printf("\t-----------------------------\n");
    	printf("\t\t1---计算个人工资\n");
    	printf("\t\t2---计算部门月工资\n");
    	printf("\t\t3---计算全校月工资\n");
    	printf("\t\t0---退出\n");
    	printf("\t-----------------------------\n");
    	printf("\t   请输入数字(0 - 3):");
        int choice;
        while(scanf("%d", &choice) == 0){
			printf("\t   输入错误！\n\t   请输入数字(0 - 3):");
			fflush(stdin);
		}
        switch (choice){
        	case 0:  return; 
            case 1: 
            {
            	char str[z];
            	printf("输入姓名：");scanf("%s", str);
				calculate_individual(phead_W, phead_F, str);
            	break; 
            }
            case 2:
            {
            	char str[z];
            	printf("输入部门：");scanf("%s", str);
            	calculate_sector(phead_W, phead_F, str);
            	break;
			} 
			case 3:
            {
            	calculate_school(phead_W, phead_F);
            	break;
			} 
     		default: continue;
        }
        system("pause");
    }
	return;
}
void menu9(Node *phead_W, Node *phead_F){
	while (1){
		system("cls");
		printf("\n\t\t打印数据\n");
		printf("\t-----------------------------\n");
    	printf("\t\t1---打印工资计算表\n");
    	printf("\t\t2---打印个人工资单\n");
    	printf("\t\t3---打印部门工资单\n");
    	printf("\t\t4---打印工资汇总表\n");
    	printf("\t\t0---退出\n");
    	printf("\t-----------------------------\n");
    	printf("\t   请输入数字(0 - 4):");
        int choice;
        while(scanf("%d", &choice) == 0){
			printf("\t   输入错误！\n\t   请输入数字(0 - 4):");
			fflush(stdin);
		}
        switch (choice){
        	case 0:  return; 
            case 1:
            {
            	print_calculate(phead_F, phead_W);
            	break; 
            }
            case 2:
            {
				char str[z];
            	printf("输入姓名：");scanf("%s", str);
            	print_individual(phead_F, phead_W, str);
            	break;
			}
			case 3:
            {
            	char str[z];
            	printf("输入部门：");scanf("%s", str);
            	print_sector(phead_F, phead_W, str); 
            	break; 
            }
            case 4:
            {
            	print_school(phead_F, phead_W);
            	break; 
            }
     		default: continue;
        }
        system("pause");
    }
	return;
}